package object3D;

import context.*;

import geometry3D.Point3D;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Line2D;



// ***************************************************************************
// *** CLASS: Etage2Trapp
// ***************************************************************************
public class LoftTrapp extends Block implements Context.Constants
{ //private static final boolean DEBUG=true; // Overriding Context.Constants.DEBUG
  
  public LoftTrapp(String ident,Point3D p0,double width,double height,double depth)
  { super(ident,p0,width,height,depth);
  }
      
  // ***************************************************************************
  // *** METHOD: getModel3D
  // ***************************************************************************
//  public /*abstract*/ Group getModel3D(Appearance appearance)
//  { Group tg=new Group();
//    tg.addChild(trinn1.getModel3D(appearance));
//    tg.addChild(trinn2.getModel3D(appearance));
//    tg.addChild(trinn3.getModel3D(appearance));
//    tg.addChild(trinn4.getModel3D(appearance));
//    tg.addChild(trinn5.getModel3D(appearance));
//    return(tg);
//  }  


  public void drawProjection(int direction,Graphics2D g,Point2D.Double origo2D,double scale,Color c)
  {

    Rectangle2D.Double r=projection(direction,origo2D,scale);
    switch(direction)
    {
      case NORTH: tegnTrapp(direction,g,r,origo2D,scale,c); break;
      case SOUTH: tegnTrapp(direction,g,r,origo2D,scale,c); break;
      case EAST: tegnTrapp(direction,g,r,origo2D,scale,c); break;
      case WEST: tegnTrapp(direction,g,r,origo2D,scale,c); break;
//      case ABOVE: drawProjectionAbove(g,r,scale,c); break;
//      case BELOW: drawProjectionBelow(g,r,scale,c); break;
//      case VCUT: drawVerticalCut(g,r,scale,c); break;
      case HCUT: tegnTrappPlan(g,r,origo2D,scale,c); break;
      default: super.drawProjection(direction,g,origo2D,scale,c);
    }  
  }

  private void tegnTrapp(int direction,Graphics2D g,Rectangle2D.Double r,Point2D.Double origo2D,double scale,Color c)
  {
  }

  private void tegnTrappPlan(Graphics2D g,Rectangle2D.Double r,Point2D.Double origo2D,double scale,Color c)
  {
//    Util.fill(g,r,Color.yellow);//c);
    g.draw(r);
    double inntrinn=r.width/8;

    // Tegn trapp
    for(int i=0;i<8;i++)
//    { double x2=r.x+0.20*i*scale;
    { double x2=r.x+i*inntrinn;
      double y1=r.y;
      double y2=r.y+r.height;
      line(g,x2,y1,x2,y2);
    }
    // Tegn pil
    { double x0=r.x+0.30*scale;
      double y=r.y+r.height/2;
      double xE=x0+0.80*scale;
      tegnPil(g,x0,y,xE,y);
    }
  }
  
  private void tegnPil(Graphics2D g,double x1,double y1,double x2,double y2)
  { double dx=(x1-x2)*0.30; // 20% av lengden
    double dy=dx/2*1.5;    
    line(g,x1,y1,x2,y2);
    line(g,x2,y2,x2+dx,y2+dy);
    line(g,x2,y2,x2+dx,y2-dy); 
  }
  
  private void line(Graphics2D g,double x1,double y1,double x2,double y2)
  { g.draw(new Line2D.Double(x1,y1,x2,y2)); }

}
